package rocketmq.transaction.trans;

import java.nio.charset.StandardCharsets;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@RocketMQTransactionListener()
public class TransMsgExecutor implements RocketMQLocalTransactionListener {

    @Override public RocketMQLocalTransactionState executeLocalTransaction(Message msg, Object arg) {
        log.info("收到的业务参数:{}", arg);
        return RocketMQLocalTransactionState.UNKNOWN;
    }

    @Override public RocketMQLocalTransactionState checkLocalTransaction(Message msg) {
        log.info("收到的消息:{}", msg.getPayload());
        String name=new String((byte[])msg.getPayload(), StandardCharsets.UTF_8);
        return RocketMQLocalTransactionState.ROLLBACK;
    }
}
